import tensorflow as tf


class AutoEncoder(object):
    def __init__(self, encoding_dim=4, image_size=784,
                 learning_rate=1e-4):
        # 先构建输入和输出，对于自编码器而言，输入和输出是一样的
        self.inputs = tf.placeholder(tf.float32,
                                     [None, image_size],
                                     name='inputs')
        self.targets = tf.placeholder(tf.float32,
                                      [None, image_size],
                                      name='targets')
        # 接着构建编码层
        with tf.name_scope('encoded'):
            self.encoded = tf.layers.dense(self.inputs,
                                           encoding_dim,
                                           activation=tf.nn.relu)
        # 解码层
        with tf.name_scope('decode'):
            self.logits = tf.layers.dense(self.encoded,
                                          image_size, 
                                          activation=None)
            self.decode = tf.nn.sigmoid(self.logits)
        # 定义loss
        with tf.name_scope('loss'):
            cost = tf.nn.sigmoid_cross_entropy_with_logits(
                labels=self.targets, logits=self.logits)
            self.loss = tf.reduce_mean(cost)
        # 定义优化器
        with tf.name_scope('train'):
            self.train_op = tf.train.AdamOptimizer(
                learning_rate=learning_rate).minimize(
                        self.loss)













